package com.ice.body.business.controller;
import com.ice.base.result.AjaxResult;
import com.ice.body.business.model.Cabinet;
import com.ice.body.business.service.CabinetService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import com.ice.base.controller.BaseController;
import org.slf4j.Logger;
import com.github.pagehelper.PageHelper;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.ice.base.result.ResponseResult;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
/**
 * Created with GuoYanBin.
 * Description:
 * Date: 2022-10-21
 * Time: 04:11
 */
@RestController
@ApiIgnore( value = "危化品柜")
public class CabinetController extends BaseController{
    //---------------------------危化品柜-----------------------start
    @Resource
    private CabinetService cabinetService;
    
    @ApiOperation(value = "危化品柜-新增")
    @PostMapping("/api/Cabinet/insert")
    public AjaxResult<Cabinet> insert_Cabinet(Cabinet model) {
        AjaxResult r = ResponseResult.success();
        try{
            Integer count  = cabinetService.insert(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }



    @ApiOperation(value = "危化品柜-更新")
    @PostMapping("/api/Cabinet/updateById")
    public AjaxResult<Cabinet> update_Cabinet(Cabinet model) {
        AjaxResult r = ResponseResult.success();
        try{
            Integer count =cabinetService.update(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "危化品柜-查询一个")
    @PostMapping("/api/Cabinet/selectById")
    public AjaxResult<Cabinet> selectById_Cabinet(@RequestParam("id") String id) {
        AjaxResult r = ResponseResult.success();
        try{
           Cabinet model = cabinetService.selectById(id);
           r.setData(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "危化品柜-查询多个")
    @PostMapping("/api/Cabinet/selectAll")
    public AjaxResult<Cabinet> selectList_Cabinet(Cabinet model) {
        AjaxResult r = ResponseResult.success();
        try{
           List<Cabinet> list = cabinetService.selectListByModel(model);
           r.setData(list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "危化品柜-查询分页")
    @PostMapping("/api/Cabinet/selectListByPageHelper")
    public AjaxResult<Cabinet> selectListByPageHelper_Cabinet(@RequestParam(name = "pageSize") Integer pageSize,
                                                              @RequestParam(name = "pageNum") Integer pageNum,
                                                              Cabinet model){
        AjaxResult r = ResponseResult.success();
        ArrayList list;
        try{
           PageHelper.startPage(pageNum, pageSize);
           list = cabinetService.selectListByModel(model);
           getReturnResultByPage(r,list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }
    //---------------------------危化品柜-----------------------end
}
